package com.jy.rhin.application.infra.assembler;

import com.jy.rhin.domain.notification.publish.entity.EnumTopicQueryFilterCompareExp;
import com.jy.rhin.domain.notification.publish.entity.SubscribeAndFilterVO;
import com.jy.rhin.sdk.dto.notification.resp.SubscribeAndFilterDto;
import org.springframework.beans.BeanUtils;
import org.springframework.util.StringUtils;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author dhl
 * @date 2022/7/7
 * @Description
 */
public class SubscribeAndFilterAssembler {
    private SubscribeAndFilterAssembler() {
    }

    /**
     * dto转vo 参数转换
     *
     * @param subscribeAndFilterList
     * @return
     */
    public static List<SubscribeAndFilterVO> toSubscribeAndFilterVo(List<SubscribeAndFilterDto> subscribeAndFilterList) {
        return subscribeAndFilterList.stream().map(dto -> {
            SubscribeAndFilterVO vo = new SubscribeAndFilterVO();
            BeanUtils.copyProperties(dto, vo);
            if (!StringUtils.isEmpty(dto.getCompareExp())) {
                vo.setCompareExp(EnumTopicQueryFilterCompareExp.valueOf(dto.getCompareExp()));
            }
            return vo;
        }).collect(Collectors.toList());
    }
}
